//
//  FriendDetailController.m
//  healthApp
//
//  Created by william mu on 12-8-29.
//  Copyright (c) 2012年 Tencent. All rights reserved.
//

#import "FriendDetailController.h"
#import "FriendSymptomCell.h"

@interface FriendDetailController ()

@end

@implementation FriendDetailController
@synthesize Param;
@synthesize tableView;

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    self.title = @"好友症状";
}

-(void) viewWillAppear:(BOOL)animated
{
    m_symptoms = [self.Param objectForKey:@"symptoms"];
}

- (void)viewDidUnload
{
    [super viewDidUnload];
    // Release any retained subviews of the main view.
    // e.g. self.myOutlet = nil;
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return [m_symptoms count];
}


-(NSDictionary*) getSymptomInfoForIndexPath:(NSIndexPath*) path
{
    NSUInteger row = [path row];
    NSDictionary* symptomInfo = (NSDictionary*)[m_symptoms objectAtIndex:row];
    return symptomInfo;
}

-(NSString*) getSymptomNameForIndexPath:(NSIndexPath*) path
{
    
    NSDictionary* symptomInfo = [self getSymptomInfoForIndexPath:path];
    NSString* symptomCode = [symptomInfo objectForKey:@"symptomType"];
    GlobalState* state = [GlobalState sharedInstance];
    NSString* symptomName = [state mapSymptomCode2Name:symptomCode];
    
    return symptomName;
}

-(NSString*) getSymptomDateForIndexPath:(NSIndexPath*) path
{
    NSDictionary* symptomInfo = [self getSymptomInfoForIndexPath:path];
    NSString* date = [symptomInfo objectForKey:@"startDate"];
    return date;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    FriendSymptomCell* cell = [self.tableView dequeueReusableCellWithIdentifier:@"SymptomCell"];
    
    if(!cell)
    {
        NSArray* ary  = (NSArray*)[[NSBundle mainBundle] loadNibNamed:@"FriendSymptomCell" owner:self options:nil];
        cell = (FriendSymptomCell*)[ary objectAtIndex:0];
    }
    cell.textLabel.font = [UIFont systemFontOfSize:15];
    cell.symptomName.text = [self getSymptomNameForIndexPath:indexPath];
    cell.symptomDate.text = [self getSymptomDateForIndexPath:indexPath];
    return cell;
}

@end
